package com.ptv.database;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.ptv.teachaclass.SplashScreenActivity;

public class BDHelper extends SQLiteOpenHelper  {

	private static final String BD_NOMBRE = "bdalumnos.db";
	private static final int BD_VERSION = 1;
	android.content.Context contexto;
	
	private static final String BD_CREAR_ALUMNOS = "CREATE TABLE alumnos (_id integer primary key autoincrement, "
			+ "nombre text not null,apellido1 text not null,apellido2 text, " 
			+ "direccion text, telefono text, email text, lunes integer, martes integer, miercoles integer," 
			+ "jueves integer, viernes integer, sabado integer, domingo integer, horaIni text,horaFin text," 
			+ "numHoras float,precioHora float, materia integer, notas text,FOREIGN KEY(materia) REFERENCES materias(_id));";
	
	private static final String BD_CREAR_MATERIAS = "CREATE TABLE materias (_id integer primary key autoincrement, "
			+ "nombre text not null);";	
	
	public BDHelper(Context context) 	{
		super(context, BD_NOMBRE, null, BD_VERSION);
		contexto = context;
	}
	
	private void lanzarActivitySplash(){
		Intent i = new Intent(contexto, SplashScreenActivity.class);
		contexto.startActivity(i);
	}
	
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(BD_CREAR_MATERIAS);	
		database.execSQL(BD_CREAR_ALUMNOS);	
		
		lanzarActivitySplash();

	}
	
	public void onUpgrade(SQLiteDatabase database, int oldVersion,
			int newVersion) {
		database.execSQL("DROP TABLE IF EXISTS alumnos");
		database.execSQL("DROP TABLE IF EXISTS materias");
		onCreate(database);
	}	
}
